<?php

/**
 * 文件由尚数增量代码引擎生成
 * @author: Shann 851188611@qq.com
 */

namespace app\admin\controller;

class MerchantCategoryBase
{
    public function index()
    {
        $merchant_categories = \app\model\MerchantCategory::field(['id', 'parent_id', 'name']);

        $merchant_categories->order('id', 'desc');

        $data['merchantCategories'] = $merchant_categories->select();

        return json(['code' => 20000, 'data' => $data]);
    }

    public function detail()
    {
        $merchant_category = \app\model\MerchantCategory::field(['id', 'parent_id', 'name']);

        $merchant_category->where('id', input('id'));

        $data['merchantCategory'] = $merchant_category->find();

        return json(['code' => 20000, 'data' => $data]);
    }

    public function create()
    {
        $param = request()->param();

        $model = new \app\model\MerchantCategory();

        $model->save($param);

        $data['merchantCategory'] = \app\model\MerchantCategory::find($model->id);

        return json(['code' => 20000, 'msg' => 'success', 'data' => $data]);
    }

    public function update()
    {
        $param = request()->param();

        $model = \app\model\MerchantCategory::find(input('id'));

        $model->save($param);

        return json(['code' => 20000, 'msg' => 'success']);
    }

    public function delete()
    {
        \app\model\MerchantCategory::destroy(function ($query) {
            $query->where('id', input('id'));
        });

        return json(['code' => 20000, 'msg' => 'success']);
    }
}
